package com.att.service.impl;

import com.att.bean.UserSpedayBean;
import com.att.dao.UserSpedayDaoMapper;
import com.att.service.UserSpedayService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service("userSpedayService")
public class UserSpedayServiceImpl implements UserSpedayService {

    @Resource
    private UserSpedayDaoMapper userSpedayDaoMapper;

    @Override
    public List<UserSpedayBean> findByCondition(UserSpedayBean bean) {
        return userSpedayDaoMapper.findByCondition(bean);
    }

    @Override
    public long findByConditionCount(UserSpedayBean bean) {
        return userSpedayDaoMapper.findByConditionCount(bean);
    }

    @Override
    @Transactional
    public boolean delete(String id) {
        List<UserSpedayBean> userSpedayBeans = new ArrayList();
        String[] idList = id.split(",");
        for (int i = 0;i < idList.length;i++){
            Integer menuId = Integer.valueOf(idList[i]);
            UserSpedayBean userSpedayBean = new UserSpedayBean();
            userSpedayBean.setId(menuId);
            userSpedayBeans.add(userSpedayBean);
        }
        return userSpedayDaoMapper.delete(userSpedayBeans);
    }

    @Override
    @Transactional
    public boolean insert(UserSpedayBean bean) {
        return userSpedayDaoMapper.insert(bean);
    }

    @Override
    public boolean update(UserSpedayBean bean) {
        return userSpedayDaoMapper.update(bean);
    }

    @Override
    public List<UserSpedayBean> findUserSpedayBean(UserSpedayBean bean) {
        return userSpedayDaoMapper.findUserSpedayBean(bean);
    }

    @Override
    public List<UserSpedayBean> findUserSpedayBeanList(UserSpedayBean bean) {
        return userSpedayDaoMapper.findUserSpedayBeanList(bean);
    }
}
